[
https://issues.apache.org/jira/browse/GEOMETRY-8?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16617356#comment-16617356
]
Gilles commented on GEOMETRY-8:
-------------------------------
{quote} more concrete example
{quote}
Thanks.
But the immediate objection would be that the precondition
{quote}a set of triangles
{quote}
is violated if one of the "things" in the set is not a triangle.
Hence
{quote}calculating surface normals
{quote}
should be attempted only after validation.
Doing otherwise would seem to mean that you never discard invalid triangles,
and each processing of the set will raise exceptions that must be caught and
ignored.
IIUC, you should "ignore" degenerate triangle/invalid objects at load time.
This assumes that _within_ the loop over the set of objects being loaded, there
is a try/catch:
{code:java}
while (!dataSource.isEmpty()) {
try {
Triangle t = loadTriangle(dataSource);
store(t);
} catch (IllegalNormException e) {
// Not a triangle.
}
}
{code}
because the normal calculation could raise an exception and we don't want the
loop to stop.
However, the same could be better achieved with
{code:java}
while (!dataSource.isEmpty()) {
Triangle t = loadTriangle(dataSource);
if (t != null) {
store(t);
}
if (!ignoreInvalidData) {
throw new InvalidTriangleException();
}
}
{code}
where method {{loadTriangle}} would perform validation (which might consist of
more than catching a single type of exception) and return a {{Triangle}}
instance only if there is a valid one in the data.
We must be very careful to not confuse
* processing code that expects sane input, in which anything unexpected should
be reported as a bug (be it invalid usage or library bug), and
* filtering of external data, where input could be invalid and _may_ be
discarded.
> Update Exception Instantiation
> ------------------------------
>
> Key: GEOMETRY-8
> URL: https://issues.apache.org/jira/browse/GEOMETRY-8
> Project: Apache Commons Geometry
> Issue Type: Task
> Reporter: Matt Juntunen
> Priority: Major
>
> Update exception instantiation following the pattern in commons-numbers, eg.
> custom private exception types created through factories. See the discussion
> on GEOMETRY-2 and the GammaException class and its use in LogBeta in
> commons-numbers.
>
> Based on discussion in GEOMETRY-9, we are going to implement our own
> exception hierarchy for this component, eg GeometryException and subclasses.
>
> Pull request: [https://github.com/apache/commons-geometry/pull/9]
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)