Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | import { Point3, ContourData, IContour } from '../../types';
import { ContourType } from '../../enums';
type ContourProps = {
id: string;
data: ContourData;
color: Point3;
segmentIndex: number;
};
/**
* The `Contour` class implements the `IContour` interface and represents a contour in 3D space.
* It holds information about the contour's id, size in bytes, points, color, and type.
* The class also provides methods to retrieve the points, color, and type of the contour.
* Each Contour is part of a ContourSet, and each ContourSet is part of a Geometry.
*/
export class Contour implements IContour {
readonly id: string;
readonly sizeInBytes: number;
points: Point3[];
color: Point3;
type: ContourType;
segmentIndex: number;
constructor(props: ContourProps) {
const { points, type } = props.data;
this.id = props.id;
this.points = points;
this.type = type;
this.color = props.color;
this.segmentIndex = props.segmentIndex;
this.sizeInBytes = this._getSizeInBytes();
}
_getSizeInBytes(): number {
let sizeInBytes = 0;
// Assuming each point is 1 byte
sizeInBytes += this.points.length * 3;
return sizeInBytes;
}
/**
* It returns the value of the points property of the data object
* @returns The points property of the data object.
*/
public getPoints(): Point3[] {
return this.points;
}
public getFlatPointsArray(): number[] {
return this.points.map((point) => [...point]).flat();
}
/**
* This function returns the color of the contour
* @returns The color of the contour
*/
public getColor(): Point3 {
return this.color;
}
/**
* It returns the type of the contour, closed or open
* @returns The type of the contour.
*/
public getType(): ContourType {
return this.type;
}
}
export default Contour;
|